//
//  AttendanceListCell.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 17/1/2.
//  Copyright © 2017年 com.xtion.crm. All rights reserved.
//

#import "AttendanceListCell.h"

#define HeadImageSize       45

#define BorderLeftRightMargin        10

#define ControlLeftRightMargin          10

#define ControlTopBottomMargin          10

@interface AttendanceListCell()
{
    UILabel *_titleLabel;
    UILabel *_contentLabel;
    UILabel *_timeLabel;
    UILabel *_dateLabel;
    
    UILabel *_lineLabel1;
    UILabel *_lineLabel2;
    
    UIColor *_textColor;
}
@end

@implementation AttendanceListCell

-(id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];

    _textColor = [UIColor redColor];
    
    CGSize s = [NSString charSizeWithSystemFontSize:16];
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, BorderLeftRightMargin, s.width*10, s.height)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.font = [UIFont systemFontOfSize:16];
    _titleLabel.textColor = _textColor;
    [self.contentView addSubview:_titleLabel];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, BorderLeftRightMargin, s.width*4, s.height)];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.font = [UIFont systemFontOfSize:16];
    _timeLabel.textColor = _textColor;
    _timeLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_timeLabel];
    
    _lineLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(0, _titleLabel.bottom + ControlTopBottomMargin, 0, 0.5)];
    _lineLabel1.backgroundColor = [UIColor grayColor];
    _lineLabel1.alpha = 0.2;
    [self.contentView addSubview:_lineLabel1];
    
    _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 0, 0)];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.font = [UIFont systemFontOfSize:16];
    _contentLabel.textColor = [UIColor colorWithHex:mcrmSAASUISkinColorTextStyle9b9b9bColor];
    _contentLabel.textColor = _textColor;
    _contentLabel.numberOfLines = 0;
    [self.contentView addSubview:_contentLabel];
    
    _lineLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0.5)];
    _lineLabel2.backgroundColor = [UIColor grayColor];
    _lineLabel2.alpha = 0.2;
    [self.contentView addSubview:_lineLabel2];
    
    s = [NSString charSizeWithSystemFontSize:13];
    _dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*8, s.height)];
    _dateLabel.backgroundColor = [UIColor clearColor];
    _dateLabel.font = [UIFont systemFontOfSize:16];
    _dateLabel.textColor = _textColor;
    _dateLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_dateLabel];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];

    _timeLabel.right = self.contentView.right - BorderLeftRightMargin;
    
    CGFloat width = self.contentView.width - BorderLeftRightMargin - BorderLeftRightMargin;
    _contentLabel.top = _lineLabel1.bottom + ControlTopBottomMargin;
    CGSize contentSize = [_contentLabel.text wrapStringSizeWithFont:_contentLabel.font forWidth:width];
    _contentLabel.height = contentSize.height;
    _contentLabel.width = width;
    
    _lineLabel1.width = self.contentView.width;
    _lineLabel2.width = self.contentView.width;
    _lineLabel2.top = _contentLabel.bottom + ControlTopBottomMargin;
    
    _dateLabel.top = _lineLabel2.bottom + ControlTopBottomMargin;
    _dateLabel.right = self.contentView.right - BorderLeftRightMargin;
}

+(CGFloat)caleHeight:(CGFloat)containWidth content:(NSString*)content;
{
    CGFloat height = 0 ;
    
    height = BorderLeftRightMargin;
    CGSize s = [NSString charSizeWithSystemFontSize:16];
    height += s.height;
    height += ControlTopBottomMargin;
    
    height += ControlTopBottomMargin;
    CGFloat width = containWidth - BorderLeftRightMargin - BorderLeftRightMargin;
    height += [content wrapStringSizeWithFont:[UIFont systemFontOfSize:16] forWidth:width].height;
    height += ControlTopBottomMargin;
    
    height += ControlTopBottomMargin;
    s = [NSString charSizeWithSystemFontSize:13];
    height += s.height;
    height += ControlTopBottomMargin;
    
    height += 0.5*2;
    
    return height;
}

- (void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
}

- (void)setCreateTime:(NSDate *)createTime
{
    _timeLabel.text = [createTime toStringDate:NSDateFormatByHm];
    _dateLabel.text = [createTime toStringDate:NSDateFormatByyMd];
}

- (void)setContent:(NSString *)content
{
    _contentLabel.text = content;
}
@end
